<?php

class McCube_FileSystem{

    protected $_dirRights  = 0777;
    protected $_fileRights = 0777;
    protected $_rootPath   = '';

    public function __construct($rootPath){
        $this->_rootPath = $rootPath.DIRECTORY_SEPARATOR;
    }

    public function createDir($dir,$rights=0777){
        if(!is_dir($dir))
            return mkdir($dir, $rights, true);
    }

    public function createDirsByThree($dirs){
        foreach($dirs as $dir=>$sdirs){
            $this->createDir($this->_rootPath.$dir);
            if(is_array($sdirs))
                $this->createDirsByThree($dir.DIRECTORY_SEPARATOR, $sdirs);
        }
    }

    public function deleteDir($dir=''){
        $dir = $this->_rootPath.$dir;
        foreach(glob($dir . '/*') as $file) {
            if(is_dir($file))
                $this->deleteDir($file);
            else
                unlink($file);
        }
        rmdir($dir);
    }


}